package com.jwaoo.mobile.view.account.update;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.bigkoo.pickerview.TimePickerView;
import com.dx.as.ToolBarOptions;
import com.dx.as.UI;
import com.dx.as.utils.DateUtil;
import com.jwaoo.mobile.R;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by jwaoo on 2017/12/18.
 */

public class UpdateActivity extends UI{
    private TextView tvBirthDay;
    private final int CODE_LOCATION = 1001;
    private final int CODE_NICKNAME = 1002;
    private final int CODE_SIGNATURE = 1003;
    @Override
    protected void onActivityCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_update_account);
        setToolBar();
        initView();
    }

    private void initView(){
        tvBirthDay = findView(R.id.tv_birthday);

    }

    private void setToolBar(){
        ToolBarOptions toolBarOptions = new ToolBarOptions();
        toolBarOptions.titleString=getString(R.string.edit_acctount_title);
        toolBarOptions.showRight=true;
        toolBarOptions.rightOptionId= R.string.Save;
        toolBarOptions.onRightClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        };
        toolBarOptions.showLeft = true;
        setToolbar(toolBarOptions);
    }


    public void onViewClick (View view){
        Bundle bundle = new Bundle();
        switch (view.getId()){
            case R.id.view_birthday:
                onSelected();
            case R.id.view_nickname:
                bundle.putInt(UpdateInfoActivity.VIEW_TYPE,UpdateInfoActivity.NICKNAME);
                goToNewActivityForResult(UpdateInfoActivity.class,CODE_NICKNAME,bundle);
                break;
            case R.id.view_location:
                bundle.putInt(UpdateInfoActivity.VIEW_TYPE,UpdateInfoActivity.LOCATION);
                goToNewActivityForResult(UpdateInfoActivity.class,CODE_LOCATION,bundle);
                break;
            case R.id.view_signature:
                bundle.putInt(UpdateInfoActivity.VIEW_TYPE,UpdateInfoActivity.SIGNATURE);
                goToNewActivityForResult(UpdateInfoActivity.class,CODE_SIGNATURE,bundle);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK){
            switch (requestCode){
                case CODE_LOCATION:
                    break;
                case CODE_NICKNAME:
                    break;
                case CODE_SIGNATURE:
                    break;
            }
        }
    }

    private void onSelected(){
        //时间选择器
        TimePickerView pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                String birthday = DateUtil.formatDateYYMMDD(date);
                tvBirthDay.setText(birthday);
            }
        })
                .setLabel("","","","","","")
                .isCyclic(true)
                .setType(new boolean[]{true,true,true,false,false,false})
                .build();
        pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
        pvTime.show();
    }
}
